<template>
	<view class="pageBg" style="min-height: 100%;">
		<Skeleton v-if="skeletonLoading" type="list"></Skeleton>
		<Head type="resumeList" title="找人才" :isBack="false">
			<ListFilters ref="refListFilters" :params="params" otherFilterType="resumeListType"
				@doSearchByDistrict="doSearchByDistrict" @doSearchByOther="doSearchByOther">
				<view class="tabBtns">
					<view class="btn ac">综合</view>
				</view>
			</ListFilters>
		</Head>
		<view class="resumeList">
			<!-- 	<resumeItem :item="item1" @toDetail="toDetail"></resumeItem>
			<resumeItem :item="item2" @toDetail="toDetail"></resumeItem> -->
			<resumeItem v-for="(item,index) in dataset" :key="item.id" :item="item" @toDetail="toDetail"></resumeItem>
			<u-loadmore v-if="dataset.length >= pagesize" class="u-loadmore" :status="finished_status"></u-loadmore>
			<Empty v-if="show_empty"></Empty>
		</view>
		<!-- 其他 -->
		<BottomNav></BottomNav>
	</view>
</template>

<script>
	import {
		obj2Param
	} from '@/utils/index'
	import http from '@/utils/http'
	import api from '@/api'
	import resumeItem from '@/components/listItem/resumeItem.vue'
	import ListFilters from '@/components/ListFilters.vue'
	import Skeleton from '@/components/Skeleton.vue'
	import {
		onShareAppMessage,
		onShareTimeline
	} from '@/utils/share.js'
	export default {
		name: 'ResumeList',
		components: {
			resumeItem,
			ListFilters,
			Skeleton
		},
		data() {
			return {
				// item1:{
				// 	age_text: 16,
				// 	companyname: "123",
				// 	current_text: "观望有好的机会再考虑",
				// 	education_text: "初中",
				// 	endtime: "2023",
				// 	experience_text: "无",
				// 	fullname: "11先生",
				// 	height: "",
				// 	high_quality: 0,
				// 	householdaddress: "",
				// 	id: 2178,
				// 	intention_district: "巴林左旗",
				// 	intention_jobs: "美容师",
				// 	intention_nature: "全职",
				// 	intention_trade: "",
				// 	intention_wage: "3K~3.5K",
				// 	jobname: "123",
				// 	major_text: "",
				// 	marriage_text: "保密",
				// 	photo_img_src: require('../static/img/empty_phot2.png'),
				// 	recent_work: "123",
				// 	refreshtime: "3小时前",
				// 	residence: "",
				// 	service_tag: "",
				// 	sex: 1,
				// 	sex_text: "男",
				// 	specialty: "123",
				// 	starttime: "2023",
				// 	stick: 0,
				// 	tag: [],
				// },
				// item2:{
				// 	age_text: 16,
				// 	companyname: "123",
				// 	current_text: "观望有好的机会再考虑",
				// 	education_text: "初中",
				// 	endtime: "2023",
				// 	experience_text: "无",
				// 	fullname: "11先生",
				// 	height: "",
				// 	high_quality: 0,
				// 	householdaddress: "",
				// 	id: 2178,
				// 	intention_district: "巴林左旗",
				// 	intention_jobs: "美容师",
				// 	intention_nature: "全职",
				// 	intention_trade: "",
				// 	intention_wage: "3K~3.5K",
				// 	jobname: "123",
				// 	major_text: "",
				// 	marriage_text: "保密",
				// 	photo_img_src: require('../static/img/empty_photo1.png'),
				// 	recent_work: "123",
				// 	refreshtime: "3小时前",
				// 	residence: "",
				// 	service_tag: "",
				// 	sex: 1,
				// 	sex_text: "男",
				// 	specialty: "123",
				// 	starttime: "2023",
				// 	stick: 0,
				// 	tag: [],
				// },
				skeletonLoading: true,
				loading: false,
				dataset: [],
				finished_status: 'loadmore',
				show_empty: false,
				params: {
					keyword: '',
					district1: '',
					district2: '',
					district3: '',
					districtName: '地区',
					experience: '',
					education: '',
					sex: '',
					minage: '',
					maxage: '',
					major: '',
					minwage: '',
					maxwage: '',
					tag: '',
					settr: '',
					wage: '',
					age: '',
					otherNum: 0
				},
				page: 1,
				pagesize: 10,
				selectResumeArrOnload: [],
				district_data: {}
			}
		},
		onPageScroll(res) {
			uni.$emit('onPageScroll', res.scrollTop)
		},
		onReachBottom() {
			this.finished_status = 'loading';
			this.page++
			this.fetchData(false)
		},
		mounted() {
			// 请求列表数据
			this.fetchData(true)
		},
		onLoad(options) {
			if (options && options.paramsCurrent && options.paramsCurrent != '') {
				this.params = JSON.parse(options.paramsCurrent)
				this.$refs.refListFilters.initShareData(this.params)
				this.fetchData(true)
			}
		},
		onShareAppMessage() {
			return onShareAppMessage({
				url: '/views/ResumeList?paramsCurrent=' + JSON.stringify(this.params),
				alias: "resumelist",
				info: {}
			})
		},
		onShareTimeline() {
			// info.imgUrl = this.info.thumb
			return onShareTimeline({
				url: '/views/ResumeList?paramsCurrent=' + JSON.stringify(this.params),
				alias: "resumelist",
				info: {}
			})
		},
		methods: {
			getColorChange() {
				let LoginOrNotLocal = uni.getStorageSync('LoginOrNot');
				let LoginOrNot = this.$store.state.LoginOrNot.toString();
				uni.setStorageSync('LoginOrNot', LoginOrNot); //更新缓存中登录状态
				if (LoginOrNot != LoginOrNotLocal) { //登录状态改变时清空缓存数据
					uni.setStorageSync('selectArr', null); //职位
					uni.setStorageSync('selectResumeArr', null); //简历 
					uni.setStorageSync('selectComArr', null); //企业
				}
				this.selectResumeArrOnload = uni.getStorageSync('selectResumeArr') == null || uni.getStorageSync(
					'selectResumeArr') == '' || uni.getStorageSync(
					'selectResumeArr') == undefined ? [] : JSON.parse(uni.getStorageSync('selectResumeArr'))
				this.selectResumeArrOnload.forEach(items => {
					this.dataset.forEach(item => {
						if (item.id == items) {
							item.clicked = true
						}
					})
				})
			},
			toDetail(id) {
				let selectResumeArr = this.selectResumeArrOnload == undefined ? [] : this.selectResumeArrOnload
				if (selectResumeArr.indexOf(id) == -1) {
					selectResumeArr.push(id)
				}
				let selectResumeArrStr = JSON.stringify(selectResumeArr)
				uni.setStorageSync('selectResumeArr', selectResumeArrStr)
				for (let i in this.dataset) {
					if (this.dataset[i].id == id && !this.dataset[i].clicked) {
						this.dataset[i].clicked = true
					}
				}
				uni.navigateTo({
					url: '/commonViews/ResumeShow?id=' + id
				})
			},
			// 地区筛选
			doSearchByDistrict(data) {
				this.district_data = data
				this.params.districtName = data.districtName
				this.params.district1 = data.district1
				this.params.district2 = data.district2
				this.params.district3 = data.district3
				this.doSearch({
					district1: data.district1,
					district2: data.district2,
					district3: data.district3
				})
			},
			doSearchByOther(data) {
				this.doSearch(data)
			},
			// 请求列表数据，init为true时直接更改dataset值，false时代表上拉加载回的数据追加进dataset
			fetchData(init) {
				this.show_empty = false
				let conditions = {
					...this.params
				}
				if (init === true) {
					this.page = 1
					this.finished_status = 'loading'
				}
				conditions.page = this.page
				conditions.pagesize = this.pagesize
				http
					.get(api.resumelist, conditions)
					.then(res => {
						if (init === true) {
							this.dataset = [...res.data.data.items]
							this.showLayer = parseInt(res.data.data.show_mask) === 1
						} else {
							this.dataset = this.dataset.concat(res.data.data.items)
						}
						this.dataset.forEach(item => {
							item.clicked = false
						})
						this.getColorChange(); //缓存数据标题是否变色
						this.skeletonLoading = false
						this.finished_status = 'loadmore';
						// 数据全部加载完成
						if (res.data.data.items.length < this.pagesize) {
							this.finished_status = 'nomore'
							if (init === false) {
								this.finished_status = 'nomore'
							} else if (res.data.data.items.length === 0) {
								this.finished_status = 'nomore'
								this.show_empty = true
							}
						}
					})
					.catch(() => {})
			},
			// 搜索通用函数
			doSearch(data) {
				for (const key in data) {
					if (this.params.hasOwnProperty(key)) {
						this.params[key] = data[key]
					}
				}
				this.params.otherNum = data.otherNum
				if (this.params.otherNum == 0) {
					this.params.gender = ''
					this.params.age = ''
					this.params.minage = ''
					this.params.maxage = ''
					this.params.maxwage = ''
					this.params.maxwage = ''
					this.params.experience = ''
					this.params.education = ''
					this.params.settr = ''
					this.params.sex = ''
					this.params.tag = ''
				}
				this.page = 1
				this.fetchData(true)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.resumeList {
		padding: 0 30rpx;
	}
</style>